﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using Fantacid303.ProcessAffinityControl.Manager.MainWindowViewModels;

namespace Fantacid303.ProcessAffinityControl.Manager.DataTemplateSelectors
{
	/// <summary>
	/// Selects a template for a <see cref="ConfigurationEntryViewModel"/> depending whether the entry is active or not
	/// </summary>
	class ConfigTreeViewDataTemplateSelector : DataTemplateSelector
	{
		/// <summary>
		/// Selects a template for a <see cref="ConfigurationEntryViewModel"/> depending whether the entry is active or not
		/// </summary>
		/// <param name="item">The data object for which to select the template.</param>
		/// <param name="container">The data-bound object.</param>
		/// <returns>
		/// Returns a <see cref="T:System.Windows.DataTemplate"/> or null. The default value is null.
		/// </returns>
		public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
		{

			var type = item.GetType();

			string templateName = null;


			if (item is ConfigurationEntryViewModel)
			{
				var data = item as ConfigurationEntryViewModel;
				templateName = data.IsActive ? "activeEntry" : "inactiveEntry";
			}
			else if (item is ConfigurationRuleViewModel)
			{
				templateName = "rule";
			}


			if (templateName == null)
				return base.SelectTemplate(item, container);
			else
				return (DataTemplate)Application.Current.MainWindow.FindResource(templateName);		
		}
	}
}
